package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.BookkeepersCashReceiptJournal;
 
 
public class BookkeepersCashReceiptJournalDAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public BookkeepersCashReceiptJournalDAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all BookkeepersCashReceiptJournal instances from the database*/
    @SuppressWarnings("unchecked")
    public List<BookkeepersCashReceiptJournal> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<BookkeepersCashReceiptJournal> list = session.selectList("BookkeepersCashReceiptJournal.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a BookkeepersCashReceiptJournal instance from the database*/
    public BookkeepersCashReceiptJournal selectById(int bkcrj_id){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            BookkeepersCashReceiptJournal BKCashReceiptJournal = (BookkeepersCashReceiptJournal) session.selectOne("BookkeepersCashReceiptJournal.getById", bkcrj_id);
            return BKCashReceiptJournal;
        } finally {
            session.close();
        }
    }
    
    /**Returns a BookkeepersCashReceiptJournal instance from the database
    public BookkeepersCashReceiptJournal getAllPending(String status){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            BookkeepersCashReceiptJournal BKCashReceiptJournal = (BookkeepersCashReceiptJournal) session.selectOne("BookkeepersCashReceiptJournal.getAllPending", status);
            return BKCashReceiptJournal;
        } finally {
            session.close();
        }
    }*/
 
    /**Updates an instance of BookkeepersCashReceiptJournal in the database*/
    public void update(BookkeepersCashReceiptJournal BKCashReceiptJournal){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("BookkeepersCashReceiptJournal.update", BKCashReceiptJournal);
            session.commit();
        } finally {
            session.close();
        }
    }
    
    /**Updates the status of BookkeepersCashReceiptJournal in the database
    public void updateStatus(int bkcrj_id){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("BookkeepersCashReceiptJournal.updateStatus", bkcrj_id);
            session.commit();
        } finally {
            session.close();
        }
    }*/
 
    /** Insert an instance of BookkeepersCashReceiptJournal into the database*/
    public void insert(BookkeepersCashReceiptJournal BKCashReceiptJournal){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("BookkeepersCashReceiptJournal.insert", BKCashReceiptJournal);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of BookkeepersCashReceiptJournal from the database*/
    public void delete(int bkcrj_id){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("BookkeepersCashReceiptJournal.deleteById", bkcrj_id);
            session.commit();
        } finally {
            session.close();
        }
    }
}